package com.conferenceroom.dto;

import lombok.Data;

import java.util.HashMap;

@Data
public class AjaxResult extends HashMap<String,Object> {
    private static final String CODE = "code";// 状态码
    private static final String MSG = "msg";
    private static final String DATA = "data";//返回给前端的数据

    //默认success
    public static AjaxResult success() {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put(CODE,200);
        ajaxResult.put(MSG,"操作成功");
        return ajaxResult;
    }

    //有数据的success
    public static AjaxResult success(Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put(CODE,200);
        ajaxResult.put(MSG,"操作成功");
        ajaxResult.put(DATA,data);
        return ajaxResult;
    }

    public static AjaxResult fail() {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put(CODE,500);
        ajaxResult.put(MSG,"操作失败");
        return ajaxResult;
    }


    public static AjaxResult fail(Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put(CODE,500);
        ajaxResult.put(MSG,"操作失败");
        ajaxResult.put(DATA,data);
        return ajaxResult;
    }
}
